<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php echo DESCRIPTION; ?>
<?php echo KEYWORD; ?>
<title><?php echo WEB_TITLE;?></title>
<link href="<?php echo WEB_URL;?>/styles/style.css" rel="stylesheet" />
<link href="<?php echo WEB_URL;?>/styles/ads.css" rel="stylesheet" />
<link type="text/css" href="<?php echo WEB_URL;?>/styles/ui-lightness/jquery-ui-1.8rc2.custom.css" rel="stylesheet" />

<!-- StyleSheet Plugin-->
<link type="text/css" href="<?php echo WEB_URL;?>/styles/jqtransform.css" rel="stylesheet" />
<link type="text/css" href="<?php echo WEB_URL;?>/styles/jquery.checkbox.css" rel="stylesheet" />


<script type="text/javascript" src="<?php echo WEB_URL;?>/scripts/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<?php echo WEB_URL;?>/scripts/jquery/jquery-ui-1.8rc2.custom.min.js"></script>

<!-- Script Plugin -->
<script type="text/javascript" src="<?php echo WEB_URL;?>/scripts/jquery/jquery.jqtransform.js"></script>
<script type="text/javascript" src="<?php echo WEB_URL;?>/scripts/jquery/jquery.checkbox.min.js"></script>
<script type="text/javascript" src="<?php echo WEB_URL;?>/scripts/jquery/jquery.hint.js"></script>
<script type="text/javascript" src="<?php echo WEB_URL;?>/scripts/jquery/jquery.cookie.js"></script>

<script type="text/javascript">
$(function(){

	$('input').hint();
		
	$('form').jqTransform({imgPath:'<?php echo WEB_URL;?>/styles/images/jqtransform/'});

 	$('input:checkbox:not([safari])').checkbox();
  	$('input:radio').checkbox();

    var cc = $.cookie('list_grid');
    if (cc == 'g') {
        $('#holder').addClass('grid');
    } else {
        $('#holder').removeClass('grid');
    }
    $('#grid').click(function() {
        $('#holder').fadeOut(300, function() {
            $(this).addClass('grid').fadeIn(300);
            $.cookie('list_grid', 'g');
        });
        return false;
    });

    $('#list').click(function() {
        $('#holder').fadeOut(300, function() {
            $(this).removeClass('grid').fadeIn(300);
            $.cookie('list_grid', null);
        });
        return false;
    });

});
</script>

</head>

<body>
	<div class="page">
    
    	<?php require_once('../header.php');?>
        <?php
        	$s = $db->select_query('SELECT * FROM setting');
			$rs= $db->fetch($s);
		?>
        <div class="content">
        	<div id="wrap_top">
            	<div id="wrap_top_left">
                	<div id="wrap_ads" >                	 
                        <div id="wrap_728x90" class="shadow"><?php get_ads(2);?></div>
                	</div>
                    
                    <div class="clear" style="margin-left:15px;"></div>
                    
                    <div id="ads_300x250">
                    	<span id="ads_300x250_1" class="shadow"><?php get_ads(3);?></span>
                    	<span id="ads_300x250_2" class="shadow"><?php get_ads(4);?></span>
                    </div>
                
                    <div id="special_ads">
                    	<div class="title"><h1>ประกาศตำแหน่งพิเศษ</h1></div>
                        <div class="clear"></div>
                    	<span id="sp_box">
                        	<div id="sp_img"><?php get_ads(5);?></div>
                            <div id="sp_title"></div>
                        </span>
                        <span id="sp_box">
                        	<div id="sp_img"><?php get_ads(6);?></div>
                            <div id="sp_title"></div>
                        </span>
                        <span id="sp_box">
                        	<div id="sp_img"><?php get_ads(7);?></div>
                            <div id="sp_title"></div>
                        </span>
                        <span id="sp_box">
                        	<div id="sp_img"><?php get_ads(8);?></div>
                            <div id="sp_title"></div>
                        </span>
                        <span id="sp_box">
                        	<div id="sp_img"><?php get_ads(9);?></div>
                            <div id="sp_title"></div>
                        </span>
                    </div>
                    
                                        
                    <div id="suggest_ads">
                    	<div class="title"><h1>ประกาศตำแหน่งแนะนำ</h1></div>
                        <div class="clear"></div>
                        <span id="sp_box">
                        	<?php get_ads(10);?>
                        </span>
                    	<span id="sp_box">
                        	<?php get_ads(11);?>
                        </span>
                        <span id="sp_box">
                        	<?php get_ads(12);?>
                        </span>
                        <span id="sp_box">
                        	<?php get_ads(13);?>
                        </span>
                        <span id="sp_box">
                        	<?php get_ads(14);?>
                        </span>                        
                    </div>
                    <div id="">
                    	<div class="title"><h1>หมวดหมู่ย่อย</h1></div>
                        <div class="clear"></div>
                        <?php
                        	$sSql = 'SELECT  `subcat`.`sub_id`,`subcat`.`sub_name` FROM  `subcat` WHERE `subcat`.`sub_active` = 1 AND `subcat`.`cat_id` = '.$_GET['cid'];
							$sQ = $db->select_query($sSql);							
						?>
                        <ul>
                        	<?php $fist = true; 
							while($sRs = $db->fetch($sQ)){
								$sub_name[$sRs['sub_id']] = $sRs['sub_name'];
							?>
                            <li style="float:left; margin-right:10px;">
                            	<strong style="font-size:16px;">
								<?php echo ($fist)? '<a href="?m=categories&p=categories&cid='.$_GET['cid'].'&c='.$_GET['c'].'&sid='.$sRs['sub_id'].'">'.$sRs['sub_name'].'</a>':', <a href="?m=categories&p=categories&cid='.$_GET['cid'].'&c='.$_GET['c'].'&sid='.$sRs['sub_id'].'">'.$sRs['sub_name'].'</a>';?></a></strong>
                           	</li>
                            <?php $fist=false; }?>
                        </ul>
                    </div>
                                        
                </div>
                <div id="wrap_top_right">
                	<div id="sub_title">หมวดหมู่สินค้า</div>
                    <div class="clear"></div>
                	<?php
                    $q = $db->select_query('SELECT * FROM '._CATEGORY); 
					
					echo '<ul class="catlist">';					
					while ($r = $db->fetch($q)) {
						if($r['cat_name']!=""){ 
					?>					
                    	<li><a href="<?php echo WEB_URL;?>/products/?m=categories&p=categories&cid=<?php echo $r['cat_id'];?>&c=<?php echo $r['cat_name'];?>">&raquo; <?php echo $r['cat_name'];?></a></li>                   	                      
					<?php
						}
					}
					echo '</ul>';
					?>
                    <?php echo $rs['f230'];?>
                </div>
            </div>
            

            
            <div id="wrap_bottom">
            	<div id="wrap_bottom_left">
                	<div class="title"><h1>ประกาศล่าสุดของหมวด <?php echo $_GET['c'];?></h1></div>
                    <div class="sub_title"><?php echo isset($sub_name[$_GET['sid']])?'หมวดหมู่ย่อย: '.$sub_name[$_GET['sid']]:'';?></div>
                    <div class="clear"></div>
                    <div id="navigation">
                        <a href="#" id="list">List view</a>
                        <a href="#" id="grid">Grid view</a>
                    </div>
                    <ul id="holder">
                    <?php
					if(!isset($_GET['sid'])){
                    $sql = "SELECT
								  `products`.*, `products_img`.`img1`, `category`.`cat_name`
								FROM
								  `products` INNER JOIN
								  `products_img` ON `products`.`pid` = `products_img`.`pid` INNER JOIN
								  `category` ON `products`.`cat_id` = `category`.`cat_id`
								WHERE
								  `products`.`cat_id` = ".$_GET['cid']."
								ORDER BY
								  `products`.`p_change_place` DESC, `products`.`p_create` DESC
								LIMIT 0, 10";
					}else{
					$sql = "SELECT
								  `products`.*, `products_img`.`img1`, `category`.`cat_name`
								FROM
								  `products` INNER JOIN
								  `products_img` ON `products`.`pid` = `products_img`.`pid` INNER JOIN
								  `category` ON `products`.`cat_id` = `category`.`cat_id` INNER JOIN
								  `subcat` ON `category`.`cat_id` = `subcat`.`cat_id`
								WHERE
								  `products`.`cat_id` = ".$_GET['cid']." AND
								  `subcat`.`sub_id` = ".$_GET['sid']."
								ORDER BY
								  `products`.`p_change_place` DESC, `products`.`p_create` DESC
								LIMIT 0, 10";
					}
					$get_cat_q = $db->select_query($sql);
					$even = "even";
					while($show_post = $db->fetch($get_cat_q)){
						$even_odd = ($even != "even")? 'class="odd"' : 'class="even"'; 
						($even == "odd")? $even = "even" : $even = "odd" ;
					?>
                    <li <?php echo $even_odd;?>>
                    <div class="post">
                    	<div class="post_img"><img src="<?php echo IMG_PATH.$show_post['img1'];?>" /></div>
                        <div class="post_title">
	                   		<div class="post_header">
                                <a href="<?php echo WEB_URL.'/products/?m=products&p=product_detail&pid='.$show_post['pid'];?>">
                                    <?php echo strip_tags(iconv_substr($show_post['p_title'],0,20,'utf-8')).'...'; ?>
                                </a> 
                                <span class="price">฿ <?php ($show_post['p_sure_price'] != 0)? print $show_post['p_sure_price'].' บาท': print $show_post['p_price'];?></span>
                            </div>
                            <div class="short-desc">
								<?php echo strip_tags(iconv_substr($show_post['p_detail'],0,240,'utf-8')).'...'; ?>
                            </div>
	                        	<span class="post_cat">Category :  <a href="<?php echo WEB_URL.'/products/?m=categories&p=categories&cid='.$show_post['cat_id'].'&c='.$show_post['cat_name'];?>"><?php echo $show_post['cat_name'];?></a></span> | <span id="post_dat"> Date Poste : <?php echo $show_post['p_create'];?></span>            
	                       	</div> 
                    </div>
                    <div class="dot"></div>
                    </li>
                    <?php	
					}
					?>
                    </ul>
                </div>
                <?php require_once('../wrap_bottom_right.php');?>
            </div>
        </div>
        
        <?php require_once('../footer.php');?>
        
    </div>
</body>
</html>